package com.htudata.home.controller;


import javax.servlet.http.HttpServletRequest;

import com.htudata.common.enums.RequestSeqEnum;
import com.htudata.common.enums.RequestStatusEnum;
import com.htudata.common.service.TokenService;
import com.htudata.convention.domain.ResponseResult;
import com.htudata.core.util.ResultGenerator;
import com.htudata.home.service.IMntEqpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class MntEqpController {

  @Autowired
  private IMntEqpService eqpService;
  
  @GetMapping({"/v1/eqp/getEdpData"})
  public ResponseResult getEdpData() {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_009.getCode(), this.eqpService.selectMntEqpData());
    } catch (Exception e) {
      log.error("getEdpData",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_009.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @GetMapping({"/v1/eqp/getHisExtre"})
  public ResponseResult getHisExtre() {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_010.getCode(), this.eqpService.selectHisExtre());
    } catch (Exception e) {
      log.error("getHisExtre",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_010.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @GetMapping({"/v1/eqp/getStationStatus"})
  public ResponseResult getStationStatus(HttpServletRequest httpRequest, @RequestParam String type, String areaCode, int status) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_019.getCode(), this.eqpService.selectStationStatus(type, areaCode, status, TokenService.getUserId(httpRequest)));
    } catch (Exception e) {
      log.error("getStationStatus",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_019.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @GetMapping({"/v1/eqp/changeUserStation"})
  public ResponseResult changeUserStation(HttpServletRequest httpRequest, @RequestParam String stationCode, @RequestParam String flag) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_025.getCode(), this.eqpService.changeUserStation(TokenService.getUserId(httpRequest), stationCode, flag));
    } catch (Exception e) {
      log.error("changeUserStation",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_025.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
}
